package com.zzptc.shop.servlet;

import com.zzptc.shop.dao.IDAO;
import com.zzptc.shop.dao.UserDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "UserManangerServlet")
public class UserManangerServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //处理乱码
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html; charset=utf-8");
       //冲数据库得到所有用户
        IDAO dao=new UserDao();
        //准备放所有用户信息
        List list=new ArrayList();
        try {
            list = dao.getAll();
        }catch (SQLException e){
            e.printStackTrace();;
        }
        //传递数据到user.jsp
        HttpSession se=request.getSession();
        se.setAttribute("allusers",list);
        //转发
        request.getRequestDispatcher("manage/user.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
